package com.orange.score.model.repository;

import android.util.Log;
import com.orange.score.constants.FilterContinentType;
import com.orange.score.model.league.League;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;

public class RepositoryManager
{
  private static String TAG = RepositoryManager.class.getName();
  List<Continent> continentList = new ArrayList();
  List<Country> countryList = new ArrayList();
  FilterContinentType filterContinentType;
  List<League> leagueList = new ArrayList();
  List<CupMatchType> matchTypesList = new ArrayList();

  public RepositoryManager()
  {
    this.filterContinentType = FilterContinentType.EUROPE;
  }

  private boolean findKeyInContent(String paramString1, String paramString2)
  {
    int k;
    int i = 0;
    int j = 0;
    if (j >= paramString1.length())
    {
      if (i != paramString1.length())
        break label54;
      k = 1;
    }
    while (true)
    {
      while (true)
      {
        return k;
        if (paramString2.contains(paramString1.substring(j, j + 1)))
          ++i;
        ++j;
      }
      label54: k = 0;
    }
  }

  public List<Country> filterCountry()
  {
    ArrayList localArrayList2;
    ArrayList localArrayList1 = new ArrayList();
    if ((this.countryList == null) || (this.countryList.size() == 0))
    {
      localArrayList2 = null;
      return localArrayList2;
    }
    Iterator localIterator = this.countryList.iterator();
    while (true)
    {
      Country localCountry;
      do
      {
        while (!(localIterator.hasNext()))
          localArrayList2 = localArrayList1;
        localCountry = (Country)localIterator.next();
      }
      while (Integer.parseInt(localCountry.continentId) != getFilterContinent().intValue());
      localArrayList1.add(localCountry);
    }
  }

  public List<Continent> findAllContinent()
  {
    return this.continentList;
  }

  public List<League> findAllLeagues()
  {
    return this.leagueList;
  }

  public Country getCountryById(String paramString)
  {
    Object localObject;
    Iterator localIterator = this.countryList.iterator();
    if (!(localIterator.hasNext()))
      localObject = null;
    while (true)
    {
      Country localCountry;
      do
      {
        return localObject;
        localCountry = (Country)localIterator.next();
      }
      while (!(localCountry.getCountryId().endsWith(paramString)));
      localObject = localCountry;
    }
  }

  public List<CupMatchType> getCupMatchTypeList()
  {
    return this.matchTypesList;
  }

  public FilterContinentType getFilterContinent()
  {
    return this.filterContinentType;
  }

  public List<League> getLeagueListByKey(List<League> paramList, String paramString)
  {
    Object localObject;
    if ((paramList == null) || (paramList.size() == 0))
    {
      localObject = null;
      return localObject;
    }
    String str = paramString.trim();
    ArrayList localArrayList = new ArrayList();
    Iterator localIterator = paramList.iterator();
    while (true)
    {
      League localLeague;
      Country localCountry;
      do
      {
        while (true)
        {
          while (!(localIterator.hasNext()))
            localObject = localArrayList;
          localLeague = (League)localIterator.next();
          if (!(findKeyInContent(str, localLeague.getLeagueName())))
            break;
          localArrayList.add(localLeague);
        }
        localCountry = getCountryById(localLeague.getCountryId());
      }
      while ((localCountry == null) || (localCountry.getCountryName() == null) || (localCountry.getCountryName().length() == 0) || (!(findKeyInContent(str, localCountry.getCountryName()))));
      localArrayList.add(localLeague);
    }
  }

  public void setFilterContinent(FilterContinentType paramFilterContinentType)
  {
    this.filterContinentType = paramFilterContinentType;
  }

  public void updateContinentDataFromStringList(String[] paramArrayOfString)
  {
    int i;
    if ((paramArrayOfString == null) || (paramArrayOfString.length == 0));
    do
    {
      return;
      this.continentList.clear();
      i = 0;
    }
    while (i >= paramArrayOfString.length);
    String[] arrayOfString = paramArrayOfString[i].split("\\^");
    if (arrayOfString.length < 2)
      Log.w(TAG, "updateContinentDataFromStringList but field count not enough, count = " + arrayOfString.length);
    while (true)
    {
      while (true)
        ++i;
      Continent localContinent = new Continent(arrayOfString[0], arrayOfString[1]);
      Log.d(TAG, "add continent = " + localContinent.toString());
      this.continentList.add(localContinent);
    }
  }

  public void updateCountryDataFromStringList(String[] paramArrayOfString)
  {
    int i;
    if ((paramArrayOfString == null) || (paramArrayOfString.length == 0));
    do
    {
      return;
      this.countryList.clear();
      i = 0;
    }
    while (i >= paramArrayOfString.length);
    String[] arrayOfString = paramArrayOfString[i].split("\\^");
    if (arrayOfString.length < 3)
      Log.w(TAG, "updateCountryDataFromStringList but field count not enough, count = " + arrayOfString.length);
    while (true)
    {
      while (true)
        ++i;
      String str1 = arrayOfString[0];
      String str2 = arrayOfString[1];
      Country localCountry = new Country(str1, arrayOfString[2], str2);
      Log.d(TAG, "add country = " + localCountry.toString());
      this.countryList.add(localCountry);
    }
  }

  public void updateGroupInfoFromStringList(String[] paramArrayOfString)
  {
    int i;
    if ((paramArrayOfString == null) || (paramArrayOfString.length == 0));
    do
    {
      return;
      this.matchTypesList.clear();
      i = 0;
    }
    while (i >= paramArrayOfString.length);
    String[] arrayOfString = paramArrayOfString[i].split("\\^");
    if (arrayOfString.length < 3)
      Log.w(TAG, "updateGroupInfoFromStringList but field count not enough, count = " + arrayOfString.length);
    while (true)
    {
      while (true)
        ++i;
      CupMatchType localCupMatchType = new CupMatchType(arrayOfString[0], arrayOfString[1], arrayOfString[2]);
      Log.d(TAG, "add CupMatchType = " + localCupMatchType.toString());
      this.matchTypesList.add(localCupMatchType);
    }
  }

  public void updateLeagueDataFromStringList(String[] paramArrayOfString)
  {
    int i;
    if ((paramArrayOfString == null) || (paramArrayOfString.length == 0));
    do
    {
      return;
      this.leagueList.clear();
      i = 0;
    }
    while (i >= paramArrayOfString.length);
    String[] arrayOfString = paramArrayOfString[i].split("\\^");
    if (arrayOfString.length < 6)
      Log.w(TAG, "updateLeagueDataFromStringList but field count not enough, count = " + arrayOfString.length);
    while (true)
    {
      while (true)
        ++i;
      String str1 = arrayOfString[0];
      String str2 = arrayOfString[1];
      String str3 = arrayOfString[2];
      String str4 = arrayOfString[3];
      String str5 = arrayOfString[4];
      List localList = Arrays.asList(arrayOfString[5].split(","));
      League localLeague = new League();
      localLeague.setLeagueId(str1);
      localLeague.setCountryId(str2);
      localLeague.setName(str3);
      localLeague.setShortName(str4);
      localLeague.setType(Integer.parseInt(str5));
      localLeague.setSeasonList(localList);
      Log.d(TAG, "add league = " + localLeague.toString());
      this.leagueList.add(localLeague);
    }
  }
}